<?php
/**
 * Created by JetBrains PhpStorm.
 * User: thuann89
 * Date: 7/7/12
 * Time: 11:22 AM
 * To change this template use File | Settings | File Templates.
 */
class OurServiceWidget extends CWidget
{
    public $title='';
    public $numOfItems = 4;
    public $category_id = '';
    public $emptyText='';
    public $contentLimited=200;

    public function getModel()
    {
        if ($this->category_id == '') {
            return null;
        }
        $criteria = new CDbCriteria();
        $criteria->with = array(
            'localeArticle' => array(
                'condition' => 'locale=:locale',
                'params' => array(':locale' => Yii::app()->language)
            ),
        );
        $criteria->compare('t.status', Article::STATUS_ACTIVE);
        $criteria->order = 't.id DESC';
        $criteria->limit=$this->numOfItems;
        if ($this->category_id!='')
        {
            $res = FSM::run('Core.Category.getRootAndChildrenIds',array('id'=>$this->category_id,'status'=>1));
            $catIds = $res->ids;
            $criteria->addInCondition('t.category_id', $catIds);
        }
        //$criteria->compare('category_id',$this->category_id);
        $models = Article::model()->findAll($criteria);
        return $models;
    }


    public  function run()
    {
        parent::run();
        $this->render('our-service',array('models'=>$this->getModel()));
    }
}
